package com.android.delivery.adapter

import android.widget.TextView
import com.android.delivery.R
import com.android.delivery.entity.CloudPrinter
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder

/**
 * 打印-云打印
 * @author: mqwang
 * @create: 3/18/21 1:33 PM
 * @Description:
 */
class PrintCloudAdapter : BaseQuickAdapter<CloudPrinter, BaseViewHolder>(R.layout.adapter_print_cloud) {

    private var mListener: OnItemClickListener? = null

    fun setOnItemClickListener(listener: OnItemClickListener) {
        mListener = listener
    }

    override fun convert(helper: BaseViewHolder?, item: CloudPrinter?) {

        helper!!.setText(R.id.tv_name, item!!.deviceId)

        val connectTv = helper.getView<TextView>(R.id.tv_connect)
        if (item.connected) {
            connectTv.setText("已连接")
            connectTv.setTextColor(mContext.resources.getColor(R.color.color_FF832C))
            connectTv.background = null
        } else {
            connectTv.setText("连接")
            connectTv.setTextColor(mContext.resources.getColor(R.color.colorWhite))
            connectTv.setBackgroundResource(R.drawable.bg_btn)
        }
        connectTv.setOnClickListener {
            if (!item.connected){
                mListener?.connDevice(item)
            }
        }
    }

    interface OnItemClickListener {
        fun connDevice(device: CloudPrinter)
    }
}